#!/bin/zsh


install() {
	DNSMASQ_INSTALLED=`/sbin/apk list dnsmasq`
	if [ -z ${DNSMASQ_INSTALLED} ]; then
		/sbin/apk add --no-cache dnsmasq 2> /dev/null
	fi
}

start() {
	PID_FILE=/run/dnsmasq.pid
	if [ ! -f ${PID_FILE} ]; then
		echo -n "start dnsmasq: "
		DNSMASQ_EXECUTABLE=`/usr/bin/which dnsmasq`
		[ -f /usr/sbin/dnsmasq ] || install
		/usr/sbin/dnsmasq -x ${PID_FILE} &
		echo ${GREEN_START}"OK"${GREEN_STOP}
	else
		echo -n "dnsmasq is running: "
		echo "[ "${GREEN_START}"OK"${GREEN_STOP}" ]"
	fi
}

main() {
	action=$1
	case $action in 
		start)
			start
			;;
		*)
	esac
}

main $@
